home *** CD-ROM | disk | FTP | other *** search
/ SGI Teleffect 1.0 / SGI Teleffect 1.0.iso / dist / patchSG0002016.idb / usr / share / catman / p_man / cat5 / dso.z.z / dso.z / dso
Encoding:
Text File  |  1998-11-02  |  88.0 KB  |  1,519 lines

  1.  
  2.  
  3.  
  4. DDDDSSSSOOOO((((5555))))                                                                  DDDDSSSSOOOO((((5555))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      DSO - Dynamic Shared Object
  10.  
  11. TTTTOOOOPPPPIIIICCCC
  12.      This man page is intended to be both a quick reference and a source of
  13.      detailed information on Dynamic Shared Objects.  It is divided into 4
  14.      sections:
  15.  
  16.      _G_e_n_e_r_a_l _I_n_f_o_r_m_a_t_i_o_n _a_n_d _O_v_e_r_v_i_e_w
  17.  
  18.      _L_i_n_k_i_n_g/_B_u_i_l_d_i_n_g _S_u_g_g_e_s_t_i_o_n_s
  19.  
  20.      _P_e_r_f_o_r_m_a_n_c_e _C_o_n_s_i_d_e_r_a_t_i_o_n_s
  21.  
  22.      _F_r_e_q_u_e_n_t_l_y _A_s_k_e_d _Q_u_e_s_t_i_o_n_s _a_n_d _D_e_t_a_i_l_e_d _D_i_s_c_u_s_s_i_o_n_s
  23.  
  24. GGGGEEEENNNNEEEERRRRAAAALLLL IIIINNNNFFFFOOOORRRRMMMMAAAATTTTIIIIOOOONNNN AAAANNNNDDDD OOOOVVVVEEEERRRRVVVVIIIIEEEEWWWW
  25.    FFFFoooorrrrmmmmaaaatttt
  26.      A DSO, or Dynamic Shared Object, is an EEEELLLLFFFF format object file, very
  27.      similar in structure to an executable program but with no "main".  It has
  28.      a shared component, consisting of shared text and read-only data; a
  29.      private component, consisting of data and the GOT (Global Offset Table);
  30.      several sections that hold information necessary to load and link the
  31.      object; and a liblist, the list of other shared objects referenced by
  32.      this object. Most of the libraries supplied by SGI are available as
  33.      dynamic shared objects.
  34.  
  35.    PPPPIIIICCCC -------- PPPPoooossssiiiittttiiiioooonnnn IIIInnnnddddeeeeppppeeeennnnddddeeeennnntttt CCCCooooddddeeee
  36.      A DSO is relocatable at runtime; it can be loaded at any virtual address.
  37.      A consequence of this is that all references to external symbols must be
  38.      resolved at runtime.  References from the private region (.e.g. from
  39.      private data) are resolved once at load-time; references from the shared
  40.      region (e.g. from shared text) must go through an indirection table (GOT)
  41.      and hence have a small performance penalty associated with them.
  42.  
  43.      Code compiled for use in a shared object is referred to as PPPPIIIICCCC whereas
  44.      non-PIC is usually referred to as nnnnoooonnnn----sssshhhhaaaarrrreeeedddd.... Non-shared code and PIC
  45.      cannot be mixed in the same object.
  46.  
  47.    WWWWhhhhaaaatttt HHHHaaaappppppppeeeennnnssss aaaatttt RRRRuuuunnnnttttiiiimmmmeeee????
  48.      EEEExxxxeeeecccc loads the main program and then loads the interpreter specified in
  49.      the main program, generally /usr/lib/libc.so.1 for old 32-bit programs,
  50.      /usr/lib32/libc.so.1 for new 32-bit programs, and /usr/lib64/libc.so.1
  51.      for 64-bit programs, and the interpreter in turns loads rrrrlllldddd((((1111)))),,,, the
  52.      runtime linking loader, which finishes the exec operation.  Starting with
  53.      main's liblist, rrrrlllldddd loads each shared object on the list that is not
  54.      marked as delay-load, reads that object's liblist, and repeats the
  55.      operation until all shared objects have been loaded, in a breadth-first
  56.      manner.  This loading process (breadth first, ignoring delay-loaded
  57.      objects) results in defining a sequence of objects.  Next, rrrrlllldddd allocates
  58.      storage for COMMON symbols and fixes up symbolic references in each
  59.      loaded object. (This is necessary because we don't know until runtime
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. DDDDSSSSOOOO((((5555))))                                                                  DDDDSSSSOOOO((((5555))))
  71.  
  72.  
  73.  
  74.      where the object will be loaded.)  To do symbol lookup of a given symbol
  75.      (in the process of of fixing up symbolic references), rld looks in each
  76.      object's dynamic symbol table in turn (according to the sequence
  77.      mentioned above).  If any ssssttttrrrroooonnnngggg symbol is found that satisfies the
  78.      reference (ie, has the name of the given symbol and is an external
  79.      definition) the lookup stops with that symbol.  If no ssssttttrrrroooonnnngggg definition
  80.      is found with that name then the first wwwweeeeaaaakkkk  symbol found is accepted as
  81.      the definition.  Next, each object's init code is executed.  Finally,
  82.      control is transferred to "__start" in the main program.
  83.  
  84.      The sequence at which the -init code is run is important to apps and DSOs
  85.      having -init code.  The default order is that the objects are taken in
  86.      the reverse order of the sequence defined in loading.  If -init code in
  87.      one DSO calls a DSO whose -init code has not yet run, then the -init code
  88.      in the called DSO is run before the called DSO routine is actually called
  89.      (thus the default order is not followed in such a case).  It is an error
  90.      for DSOs to mutually call one another (even indirectly) from within init
  91.      sections since neither init section can complete first in such a case
  92.      (_r_l_d catches this and invokes a fatal-error routine).  The init code in
  93.      delay-loaded DSOs is not run till the DSO is actually loaded (when some
  94.      routine in it is called it will be loaded).
  95.  
  96.      _d_l_o_p_e_n()ed and _s_g_i_d_l_o_p_e_n__v_e_r_s_i_o_n()ed DSOs are ignored in the symbol
  97.      lookup mentioned above.  As are symbols in any DSO which is loaded at run
  98.      time by being on the library list of a _d_l_o_p_e_n()ed or
  99.      _s_g_i_d_l_o_p_e_n__v_e_r_s_i_o_n()ed DSO.  However, if a DSO has its symbols visible for
  100.      any reason (say it was in the main program liblist) that DSO is not then
  101.      hidden just because it is *also* on the library list of a _d_l_o_p_e_n()ed or
  102.      _s_g_i_d_l_o_p_e_n__v_e_r_s_i_o_n()ed DSO.
  103.  
  104.      Be sure to read about qqqquuuuiiiicccckkkkssssttttaaaarrrrtttt,,,, ddddeeeellllaaaayyyyeeeedddd llllooooaaaaddddssss,,,, ssssggggiiiiddddllllaaaadddddddd((((3333)))),,,,
  105.      ssssggggiiiiddddllllooooppppeeeennnn____vvvveeeerrrrssssiiiioooonnnn((((3333)))),,,, and ddddllllooooppppeeeennnn((((3333)))) as each can affect this general
  106.      process.
  107.  
  108. LLLLIIIINNNNKKKKIIIINNNNGGGG //// BBBBUUUUIIIILLLLDDDDIIIINNNNGGGG DDDDYYYYNNNNAAAAMMMMIIIICCCC SSSSHHHHAAAARRRREEEEDDDD OOOOBBBBJJJJEEEECCCCTTTTSSSS
  109.    EEEExxxxaaaammmmpppplllleeee
  110.      Suppose your library is in an archive _l_i_b_f_o_o._a of object files all of
  111.      which have been compiled -shared; and it references symbols found in
  112.      _l_i_b_c._s_o._1, _l_i_b_g_l._s_o, _l_i_b_X_1_1._s_o and _l_i_b_n_e_t_l_s._s_o though most programs will
  113.      never use the path that requires _l_i_b_n_e_t_l_s._s_o. SGI recommends building
  114.      your DSO, _l_i_b_f_o_o._s_o, in the following way:
  115.  
  116.           ld                           \
  117.                -elf                    \
  118.                -shared                 \
  119.                -no_unresolved          \
  120.                -rdata_shared           \
  121.                -soname libfoo.so            \
  122.                -o libfoo.so            \
  123.                -all libfoo.a           \
  124.                -lX11                   \
  125.                -delay_load -lnetls     \
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. DDDDSSSSOOOO((((5555))))                                                                  DDDDSSSSOOOO((((5555))))
  137.  
  138.  
  139.  
  140.                -lc                     \
  141.                -lgl
  142.  
  143.      This builds a DSO called libfoo.so that will request rrrrlllldddd to load
  144.      libc.so.1, libX11.so, and libgl.so  whenever libfoo.so is loaded and will
  145.      load libnetls.so if it is ever referenced.
  146.  
  147.      NNNNOOOOTTTTEEEE::::
  148.           If you have any C++ object files among the objects making up your
  149.           DSO, you must replace lllldddd in the above command with CCCCCCCC.  I.e. your
  150.           command becomes:
  151.  
  152.                CC -elf -shared ... -o libfoo.so -all libfoo.a ...
  153.  
  154.           However, you do not have to do anything special at all to _u_s_e such
  155.           C++ DSOs when linking other programs against these DSOs. You can
  156.           link C++ DSOs into C, C++, or Fortran programs using your usual link
  157.           commands or link other DSOs against these C++ DSOs without taking
  158.           any special action.
  159.  
  160.           For example, the following link works, with the preceding C++ DSO
  161.           libfoo.so being properly initialized by rrrrlllldddd at program startup:
  162.  
  163.                f77 fortran_prog.o -lfoo
  164.  
  165.    CCCCoooonnnnttttrrrroooolllllllliiiinnnngggg TTTThhhheeee SSSSyyyymmmmbbbboooollllssss EEEExxxxppppoooorrrrtttteeeedddd BBBByyyy AAAA DDDDyyyynnnnaaaammmmiiiicccc SSSShhhhaaaarrrreeeedddd OOOObbbbjjjjeeeecccctttt
  166.      One of the benefits of using dynamic shared objects is the ability to
  167.      release new versions of that object and still have objects that were
  168.      linked against the old version, work with the new version. This is
  169.      impossible to guarantee, if the set of symbols exported by an object
  170.      cannot easily be understood by the object's creator.  lllldddd provides several
  171.      options that help the developer control which symbols are exported by a
  172.      dynamic shared object.
  173.  
  174.      By default lllldddd does not export symbols that are supplied by a linked-in
  175.      archive or dynamic shared object. The developer is probably only a
  176.      consumer of the linked-in object, not an exporter. In a subsequent
  177.      release, the developer may not require the linked-in object and if the
  178.      symbols provided by the linked-in object had been exported by the
  179.      developer's object, the new object would not longer be upwardly
  180.      compatible with the original version. This behavior can be overridden
  181.      using the ----eeeexxxxppppoooorrrrttttssss option.  This default-symbol-hiding behavior, with
  182.      respect to archives, is also overridden when building a dynamic shared
  183.      object from an archive using the ----aaaallllllll option.
  184.  
  185.      The developer has greater control over the list of symbols that are
  186.      exported using options ----eeeexxxxppppoooorrrrtttteeeedddd____ssssyyyymmmmbbbboooollll,,,, ----eeeexxxxppppoooorrrrttttssss____ffffiiiilllleeee,,,, ----hhhhiiiiddddddddeeeennnn____ssssyyyymmmmbbbboooollll,
  187.      or ----hhhhiiiiddddeeeessss____ffffiiiilllleeee.  The first two options let the developer specifically
  188.      list the symbols that are to be exported by the dynamic shared object.
  189.      The ----eeeexxxxppppoooorrrrtttteeeedddd____ssssyyyymmmmbbbboooollll option is followed by a comma separated list of
  190.      names.  The ----eeeexxxxppppoooorrrrttttssss____ffffiiiilllleeee option gives a filename that contains a space
  191.      separated (including newlines) list of names. If any symbols are
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. DDDDSSSSOOOO((((5555))))                                                                  DDDDSSSSOOOO((((5555))))
  203.  
  204.  
  205.  
  206.      specifically exported, then only those symbols will be exported. All
  207.      other symbols are automatically hidden.  The last two options let the
  208.      developer specify a list of symbols that are to be not exported by the
  209.      dynamic shared object.
  210.  
  211.      There are two consequences of hiding symbols. First, those symbols will
  212.      not provide resolution to any undefined symbols in an object that links
  213.      in the dynamic shared object. Second , any references to that symbol
  214.      within the dynamic shared object will be resolved internally to the
  215.      hidden symbol.
  216.  
  217.    RRRRuuuulllleeeessss OOOOffff TTTThhhhuuuummmmbbbb
  218.      Use ----nnnnoooo____uuuunnnnrrrreeeessssoooollllvvvveeeedddd to find unresolved symbols. While it is not always
  219.      possible to supply all the shared objects that will be referenced by
  220.      libfoo.so on the link line, in general libraries should be self-
  221.      contained. This is especially true for subsequent releases of a dynamic
  222.      shared object. If a dynamic shared object has any unresolved references,
  223.      they must be resolved by some other loaded object. Having unresolved
  224.      symbols invites disaster since there is no guarantee that the symbols
  225.      will be resolved and thus the application may not run.
  226.  
  227.      Link against the minimum set of .so's needed. Loading a shared object
  228.      does carry a cost. Linking against unneeded dynamic shared objects causes
  229.      them to be loaded even if they are never referenced.  lllldddd warns when you
  230.      have linked against a dynamic shared object that resolves no symbols.
  231.  
  232.      When building a C++ dynamic shared object, specify ----eeeexxxxppppoooorrrrttttssss for any
  233.      dynamic shared object that provides the definitions of classes that
  234.      classes in the object being created derive from. Specifying ----eeeexxxxppppoooorrrrttttssss in
  235.      this case ensures that consumers of the object being created can create
  236.      subclasses of classes provided by that object, without having to know the
  237.      complete set of dynamic shared objects that will need to be loaded. Using
  238.      the ----eeeexxxxppppoooorrrrttttssss flag in this case may bring in unwanted symbols. Use the
  239.      ----eeeexxxxppppoooorrrrtttteeeedddd____ssssyyyymmmmbbbboooollll,,,, ----eeeexxxxppppoooorrrrttttssss____ffffiiiilllleeee,,,, ----hhhhiiiiddddddddeeeennnn____ssssyyyymmmmbbbboooollll, or ----hhhhiiiiddddeeeessss____ffffiiiilllleeee options
  240.      where appropriate.
  241.  
  242.      Use ----rrrrddddaaaattttaaaa____sssshhhhaaaarrrreeeedddd to move all read-only data into the shared segment.
  243.      Unfortunately, there are many programs that write to supposedly read-only
  244.      data; for this reason, ----rrrrddddaaaattttaaaa____sssshhhhaaaarrrreeeedddd is off by default. The ----
  245.      uuuusssseeee____rrrreeeeaaaaddddoooonnnnllllyyyy____ccccoooonnnnsssstttt compiler option is on by default.
  246.  
  247.      If you reference the gl, have it last in the link line. Often _l_i_b_g_l._s_o
  248.      cannot be quickstarted (see below); putting it last allows all the
  249.      "upstream" objects to still be quickstarted. You can also choose to
  250.      delay-load _l_i_b_g_l._s_o. This still allows your application to quickstart.
  251.  
  252.      Anytime a "downstream" shared object (a referenced object) changes, you
  253.      should relink in order to quickstart, or run the requickstart tool rrrrqqqqssss((((1111))))
  254.      on the object.
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.                                                                         PPPPaaaaggggeeee 4444
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268. DDDDSSSSOOOO((((5555))))                                                                  DDDDSSSSOOOO((((5555))))
  269.  
  270.  
  271.  
  272.      Try to minimize inter-DSO data references.
  273.  
  274.      Try to minimize the use of global data. In DSOs, it is generally more
  275.      efficient to malloc space when needed rather than use a large static data
  276.      structure.
  277.  
  278.      Try to pack data together that is likely to be unmodified. This allows
  279.      the kernel to make more of the data pages shared, copy-on-write.
  280.  
  281.      Use the ----ddddeeeellllaaaayyyy____llllooooaaaadddd option on any shared object on the link line that is
  282.      not often used. This adds a small performance penalty for references to
  283.      it, but can save time and memory for those programs that don't use it.
  284.  
  285.      Do not call sssspppprrrroooocccc from any code that may be executed at init time.
  286.  
  287. PPPPEEEERRRRFFFFOOOORRRRMMMMAAAANNNNCCCCEEEE CCCCOOOONNNNSSSSIIIIDDDDEEEERRRRAAAATTTTIIIIOOOONNNNSSSS
  288.    QQQQuuuuiiiicccckkkkssssttttaaaarrrrtttt
  289.      When building a shared object or an executable, lllldddd assigns addresses to
  290.      the object and attempts to resolve all references.  At runtime, if rrrrlllldddd
  291.      verifies that the same set of objects are loaded at the original
  292.      addresses, then rrrrlllldddd can skip all the runtime relocation work and let the
  293.      program run. This saves time by skipping doing the relocations and saves
  294.      memory since rrrrlllldddd does not have to read in the sections that hold the
  295.      relocation information.
  296.  
  297.      At static link time, lllldddd resolves each unresolved function call to a stub
  298.      routine which references an rrrrlllldddd function called llllaaaazzzzyyyy____tttteeeexxxxtttt____rrrreeeessssoooollllvvvveeee(((()))).... When
  299.      invoked at runtime, it performs the relocation needed for all future
  300.      calls to the original function. In this way, more programs can quickstart
  301.      even if some of the function references are not resolved at static link
  302.      time.
  303.  
  304.      Quickstart fails whenever the dynamic shared objects on a system do not
  305.      match the objects used when linking and application or the shared objects
  306.      that it depends on.  This will occur whenever a new version of a dynamic
  307.      shared object is released.  When quickstart fails rrrrlllldddd has to do a
  308.      significant amount of work.  The rrrrqqqqssss((((1111)))) command can be used  to
  309.      recalculate the quickstart information associated with an application or
  310.      a dynamic shared object.  rrrrqqqqssss must be called in proper order so that
  311.      dynamic shared objects on an objects liblist are requickstarted before
  312.      the object ir requickstarted. rrrrqqqqssss will rewrite the object it is
  313.      requickstarting back in place.  It is possible to mark an object as non-
  314.      requickstartable by using the ----nnnnoooo____rrrrqqqqssss flag to lllldddd....
  315.  
  316.    AAAAvvvvooooiiiiddddiiiinnnngggg GGGGrrrraaaattttuuuuiiiittttoooouuuussss SSSShhhhaaaarrrreeeedddd OOOObbbbjjjjeeeecccctttt LLLLooooaaaaddddssss
  317.      Since for each shared object that is loaded rrrrlllldddd does a considerable
  318.      amount of work and can use up large amounts of real memory it is
  319.      advantageous to not link against shared objects that are not needed.
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.                                                                         PPPPaaaaggggeeee 5555
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334. DDDDSSSSOOOO((((5555))))                                                                  DDDDSSSSOOOO((((5555))))
  335.  
  336.  
  337.  
  338.    RRRReeeedddduuuucccciiiinnnngggg tttthhhheeee nnnnuuuummmmbbbbeeeerrrr ooooffff CCCCoooonnnnfffflllliiiiccccttttssss
  339.      Whenever more than one shared object (including the main program) needed
  340.      by an executable define and use the same name for a symbol, this is
  341.      called a ccccoooonnnnfffflllliiiicccctttt and the name for which multiple definitions exist is
  342.      recorded in your program in the section named ".conflict"  The names of
  343.      all conflicting symbols pertaining to a program can be obtained via the
  344.      ----DDDDcccc flag to eeeellllffffdddduuuummmmpppp.... One example of a conflict is the routine mmmmaaaalllllllloooocccc
  345.      which is defined both in lllliiiibbbbcccc....ssssoooo....1111 and in lllliiiibbbbmmmmaaaalllllllloooocccc....ssssoooo....
  346.  
  347.      Conflicts represent extra work to be done at startup, because the
  348.      presence of a conflict means that the objects in the link may not have
  349.      chosen a consistent instance of the symbol in question.  This extra work
  350.      is memory-intensive, since even the presence of one conflict may mean
  351.      that many pages of memory must be examined by rrrrlllldddd which would otherwise
  352.      have not been needed for a quickstarting program. The ----qqqquuuuiiiicccckkkkssssttttaaaarrrrtttt____iiiinnnnffffoooo
  353.      flag makes lllldddd print out a warning about every conflict it finds and the
  354.      names of two of the objects in which it is defined. Of course, sometimes
  355.      conflicts are a necessary part of the design of certain applications.
  356.  
  357.  
  358.    ddddllllooooppppeeeennnn((((3333)))),,,, ssssggggiiiiddddllllooooppppeeeennnn____vvvveeeerrrrssssiiiioooonnnn((((3333)))),,,, ssssggggiiiiddddllllaaaadddddddd((((3333)))),,,, aaaannnndddd ddddeeeellllaaaayyyyeeeedddd llllooooaaaaddddssss
  359.      The overhead associated with objects that are referenced but seldom
  360.      actually used can be mitigated by using ddddllllooooppppeeeennnn((((3333)))),,,, ssssggggiiiiddddllllooooppppeeeennnn____vvvveeeerrrrssssiiiioooonnnn((((3333)))),,,,
  361.      ssssggggiiiiddddllllaaaadddddddd((((3333)))),,,, or ddddeeeellllaaaayyyyeeeedddd llllooooaaaaddddssss.... The use of any of these, delays the
  362.      loading of a shared object (and the objects on it's liblist) until it is
  363.      actually referenced.  The most convenient is the ----ddddeeeellllaaaayyyy____llllooooaaaadddd option to
  364.      lllldddd.... All three require that there be no references from any other objects'
  365.      data section to the delay loaded shared object.
  366.  
  367.  
  368. FFFFRRRREEEEQQQQUUUUEEEENNNNTTTTLLLLYYYY AAAASSSSKKKKEEEEDDDD QQQQUUUUEEEESSSSTTTTIIIIOOOONNNNSSSS
  369. List of Questions:
  370.  
  371.    1111))))  WWWWhhhhaaaatttt iiiissss DDDDSSSSOOOO????
  372.    2222))))  HHHHoooowwww ddddoooo ddddyyyynnnnaaaammmmiiiicccc sssshhhhaaaarrrreeeedddd oooobbbbjjjjeeeeccccttttssss ccccoooommmmppppaaaarrrreeee wwwwiiiitttthhhh sssshhhhaaaarrrreeeedddd lllliiiibbbbrrrraaaarrrriiiieeeessss????
  373.    3333))))  HHHHoooowwww ddddoooo IIII mmmmaaaaiiiinnnnttttaaaaiiiinnnn bbbbiiiinnnnaaaarrrryyyy ccccoooommmmppppaaaattttiiiibbbbiiiilllliiiittttyyyy bbbbeeeettttwwwweeeeeeeennnn vvvveeeerrrrssssiiiioooonnnnssss ooooffff
  374.      DSOs?"
  375.  
  376.    4444))))  UUUUnnnnddddeeeerrrr wwwwhhhhiiiicccchhhh vvvveeeerrrrssssiiiioooonnnnssss ooooffff tttthhhheeee OOOOSSSS ccccaaaannnn IIII uuuusssseeee DDDDSSSSOOOO????
  377.    5555))))  WWWWhhhhaaaatttt oooobbbbjjjjeeeecccctttt----ffffiiiilllleeee ffffoooorrrrmmmmaaaatttt ddddooooeeeessss DDDDSSSSOOOO uuuusssseeee????
  378.    6666))))  HHHHoooowwww ddddoooo IIII iiiinnnnssssttttaaaallllllll tttthhhheeee ttttoooooooollllssss ssssoooo IIII ccccaaaannnn uuuusssseeee DDDDSSSSOOOO oooonnnn mmmmyyyy ssssyyyysssstttteeeemmmm????
  379.    7777))))  HHHHoooowwww ddddoooo IIII bbbbuuuuiiiilllldddd aaaannnn eeeexxxxeeeeccccuuuuttttaaaabbbblllleeee tttthhhhaaaatttt uuuusssseeeessss aaaa sssshhhhaaaarrrreeeedddd oooobbbbjjjjeeeecccctttt????
  380.    8888))))  HHHHoooowwww ddddoooo IIII bbbbuuuuiiiilllldddd aaaannnn eeeexxxxeeeeccccuuuuttttaaaabbbblllleeee tttthhhhaaaatttt ddddooooeeeessssnnnn''''tttt uuuusssseeee sssshhhhaaaarrrreeeedddd
  381.      linking?"
  382.  
  383.    9999))))  HHHHoooowwww ddddoooo IIII tttteeeellllllll iiiiffff aaaannnn eeeexxxxeeeeccccuuuuttttaaaabbbblllleeee wwwwiiiillllllll uuuusssseeee ddddyyyynnnnaaaammmmiiiicccc lllliiiinnnnkkkkiiiinnnngggg????
  384.    11110000)))) HHHHoooowwww ddddoooo IIII bbbbuuuuiiiilllldddd aaaa sssshhhhaaaarrrreeeedddd oooobbbbjjjjeeeecccctttt????
  385.    11111111)))) WWWWhhhheeeerrrreeee ddddooooeeeessss tttthhhheeee ssssyyyysssstttteeeemmmm llllooooooookkkk ffffoooorrrr sssshhhhaaaarrrreeeedddd oooobbbbjjjjeeeeccccttttssss aaaatttt rrrruuuunnnnttttiiiimmmmeeee????
  386.    11112222)))) WWWWhhhhaaaatttt iiiissss QQQQuuuuiiiicccckkkkssssttttaaaarrrrtttt????
  387.    11113333)))) WWWWhhhhaaaatttt iiiissss tttthhhheeee ssssoooo____llllooooccccaaaattttiiiioooonnnnssss ffffiiiilllleeee????
  388.  
  389.  
  390.  
  391.  
  392.  
  393.                                                                         PPPPaaaaggggeeee 6666
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400. DDDDSSSSOOOO((((5555))))                                                                  DDDDSSSSOOOO((((5555))))
  401.  
  402.  
  403.  
  404.    11114444)))) WWWWhhhhaaaatttt ddddiiiirrrreeeeccccttttiiiivvvveeeessss ccccaaaannnn bbbbeeee ppppuuuutttt iiiinnnn aaaa ssssoooo____llllooooccccaaaattttiiiioooonnnnssss ffffiiiilllleeee????
  405.    11115555)))) WWWWhhhhaaaatttt iiiissss ////uuuussssrrrr////lllliiiibbbb////ssssoooo____llllooooccccaaaattttiiiioooonnnnssss????
  406.    11116666)))) IIIIffff IIII ddddoooonnnn''''tttt hhhhaaaavvvveeee aaaa vvvvaaaalllliiiidddd ssssoooo____llllooooccccaaaattttiiiioooonnnnssss,,,, ccccaaaannnn IIII ggggeeeennnneeeerrrraaaatttteeee oooonnnneeee ffffrrrroooommmm
  407.      all the .so's in, say, /usr/lib?"
  408.  
  409.    11117777)))) HHHHoooowwww eeeexxxxppppeeeennnnssssiiiivvvveeee iiiissss iiiitttt ((((aaaatttt rrrruuuunnnnttttiiiimmmmeeee)))) ttttoooo NNNNOOOOTTTT uuuusssseeee tttthhhheeee
  410.      -update_registry option?"
  411.  
  412.    11118888)))) HHHHoooowwww aaaannnndddd wwwwhhhheeeennnn wwwwiiiillllllll QQQQuuuuiiiicccckkkkssssttttaaaarrrrtttt bbbbeeee uuuusssseeeedddd????
  413.    11119999)))) WWWWhhhhaaaatttt aaaabbbboooouuuutttt rrrruuuunnnn----ttttiiiimmmmeeee llllooooaaaaddddiiiinnnngggg uuuunnnnddddeeeerrrr uuuusssseeeerrrr ccccoooonnnnttttrrrroooollll????
  414.    22220000)))) WWWWhhhhaaaatttt bbbbeeeennnneeeeffffiiiittttssss wwwwiiiillllllll IIII ggggeeeetttt ffffrrrroooommmm DDDDSSSSOOOO????
  415.    22221111)))) WWWWhhhhaaaatttt ccccoooossssttttssss aaaarrrreeee aaaassssssssoooocccciiiiaaaatttteeeedddd wwwwiiiitttthhhh DDDDSSSSOOOO????
  416.    22222222)))) WWWWhhhhaaaatttt iiiissss tttthhhheeee ----KKKKPPPPIIIICCCC ooooppppttttiiiioooonnnn????
  417.    22223333)))) MMMMuuuusssstttt mmmmaaaaiiiinnnn pppprrrrooooggggrrrraaaammmmssss wwwwhhhhiiiicccchhhh wwwwaaaannnntttt ttttoooo uuuusssseeee DDDDSSSSOOOOssss uuuusssseeee ----KKKKPPPPIIIICCCC ffffoooorrrr
  418.      compilation?"
  419.  
  420.    22224444)))) HHHHoooowwww ddddoooo IIII cccchhhhaaaannnnggggeeee mmmmyyyy aaaasssssssseeeemmmmbbbbllllyyyy llllaaaannnngggguuuuaaaaggggeeee ssssoooouuuurrrrcccceeeessss ttttoooo uuuusssseeee ----KKKKPPPPIIIICCCC????
  421.    22225555)))) CCCCaaaannnn IIII mmmmiiiixxxx IIIIRRRRIIIIXXXX 4444 ssssttttaaaattttiiiicccc sssshhhhaaaarrrreeeedddd lllliiiibbbbrrrraaaarrrriiiieeeessss wwwwiiiitttthhhh DDDDSSSSOOOOssss????
  422.    22226666)))) WWWWhhhhaaaatttt ooooppppttttiiiioooonnnnssss ddddoooo IIII hhhhaaaavvvveeee wwwwhhhheeeennnn bbbbuuuuiiiillllddddiiiinnnngggg aaaa sssshhhhaaaarrrreeeedddd oooobbbbjjjjeeeecccctttt????
  423.    22227777)))) WWWWhhhhaaaatttt ppppiiiittttffffaaaallllllllssss sssshhhhoooouuuulllldddd IIII kkkknnnnoooowwww aaaabbbboooouuuutttt wwwwhhhhiiiicccchhhh aaaarrrreeee aaaassssssssoooocccciiiiaaaatttteeeedddd wwwwiiiitttthhhh
  424.      DSO?"
  425.  
  426.    22228888)))) WWWWhhhhaaaatttt sssshhhhoooouuuulllldddd IIII ddddoooo aaaabbbboooouuuutttt aaaa GGGGOOOOTTTT oooovvvveeeerrrrfffflllloooowwww????
  427.    22229999)))) HHHHoooowwww aaaarrrreeee mmmmuuuullllttttiiiipppplllleeee vvvveeeerrrrssssiiiioooonnnnssss ooooffff DDDDSSSSOOOOssss ssssuuuuppppppppoooorrrrtttteeeedddd????
  428.    33330000)))) WWWWhhhhyyyy aaaarrrreeee tttthhhheeee gggglllloooobbbbaaaallll oooobbbbjjjjeeeeccccttttssss iiiinnnn mmmmyyyy CCCC++++++++ DDDDSSSSOOOO nnnnooootttt bbbbeeeeiiiinnnngggg iiiinnnniiiittttiiiiaaaalllliiiizzzzeeeedddd????
  429.    33331111)))) WWWWhhhheeeerrrreeee ccccaaaannnn IIII ffffiiiinnnndddd mmmmoooorrrreeee ddddooooccccuuuummmmeeeennnnttttaaaattttiiiioooonnnn oooonnnn DDDDSSSSOOOO????
  430.    1111))))  WWWWhhhhaaaatttt iiiissss DDDDSSSSOOOO????
  431.      DSO stands for Dynamic Shared Object.  DSO provides a capability similar
  432.      to static shared libraries under IRIX4 and earlier, e.g., it gives
  433.      applications the ability to share the text of heavily used libraries,
  434.      which need not be included in the executable file.  However DSO has two
  435.      important distinctions from static shared libraries.
  436.  
  437.    2222))))  HHHHoooowwww ddddoooo ddddyyyynnnnaaaammmmiiiicccc sssshhhhaaaarrrreeeedddd oooobbbbjjjjeeeeccccttttssss ccccoooommmmppppaaaarrrreeee wwwwiiiitttthhhh ssssttttaaaattttiiiicccc sssshhhhaaaarrrreeeedddd lllliiiibbbbrrrraaaarrrriiiieeeessss????
  438.      First, a dynamic shared object contains only position-independent code,
  439.      so that it may be mapped into the virtual address space of different
  440.      processes at different addresses and still be shared.  Second, dynamic
  441.      shared objects, and indeed the executable itself are mapped in by a
  442.      runtime loader, rld, which resides in memory in the same address space as
  443.      the executable.  This gives the system the ability to change the binding
  444.      of symbols during executions, at the request of the executing program.
  445.  
  446.    3333))))  HHHHoooowwww ddddoooo IIII mmmmaaaaiiiinnnnttttaaaaiiiinnnn bbbbiiiinnnnaaaarrrryyyy ccccoooommmmppppaaaattttiiiibbbbiiiilllliiiittttyyyy bbbbeeeettttwwwweeeeeeeennnn vvvveeeerrrrssssiiiioooonnnnssss ooooffff DDDDSSSSOOOOssss????
  447.      As long as the shared objects maintain the same exported symbols, or
  448.      perhaps add new symbols without removing any or changing semantics, and
  449.      don't change exported structures, they will be binary compatible.
  450.      Ordering of symbols, routines and global data are irrelevant.
  451.  
  452.    4444))))  UUUUnnnnddddeeeerrrr wwwwhhhhiiiicccchhhh vvvveeeerrrrssssiiiioooonnnnssss ooooffff tttthhhheeee OOOOSSSS ccccaaaannnn IIII uuuusssseeee DDDDSSSSOOOO????
  453.      DSO is available under IRIX versions 5.0 and later.  Programs built with
  454.      DSO will not work on earlier version of IRIX.
  455.  
  456.  
  457.  
  458.  
  459.                                                                         PPPPaaaaggggeeee 7777
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466. DDDDSSSSOOOO((((5555))))                                                                  DDDDSSSSOOOO((((5555))))
  467.  
  468.  
  469.  
  470.    5555))))  WWWWhhhhiiiicccchhhh oooobbbbjjjjeeeecccctttt----ffffiiiilllleeee ffffoooorrrrmmmmaaaatttt ddddooooeeeessss DDDDSSSSOOOO uuuusssseeee????
  471.      DSO uses the ELF object file format, as defined in the SVR4 ABI.  ELF
  472.      objects cannot be run under IRIX 4.0.5 or earlier.
  473.  
  474.    6666))))  HHHHoooowwww ddddoooo IIII iiiinnnnssssttttaaaallllllll tttthhhheeee ttttoooooooollllssss ssssoooo IIII ccccaaaannnn uuuusssseeee DDDDSSSSOOOO oooonnnn mmmmyyyy ssssyyyysssstttteeeemmmm????
  475.      IRIX 5.0 and later releases all support and use DSOs. In order to compile
  476.      and build shared objects you will need to have the Developer's Option
  477.      installed.
  478.  
  479.    7777))))  HHHHoooowwww ddddoooo IIII bbbbuuuuiiiilllldddd aaaannnn eeeexxxxeeeeccccuuuuttttaaaabbbblllleeee tttthhhhaaaatttt uuuusssseeeessss aaaa sssshhhhaaaarrrreeeedddd oooobbbbjjjjeeeecccctttt????
  480.               cc myfile.c -lmine
  481.  
  482.      This will link you with libmine.so and also with libc.so.1, if either are
  483.      available. If no libmine.so is available, but there is a libmine.a, the
  484.      libmine.a will be used along with libc.so.1, and you will still get
  485.      dynamic linking. To be explicit, add the ----ccccaaaallllllll____sssshhhhaaaarrrreeeedddd flag to the cc
  486.      line:
  487.  
  488.               cc -call_shared myfile.c -lmine
  489.  
  490.    8888))))  HHHHoooowwww ddddoooo IIII bbbbuuuuiiiilllldddd aaaannnn eeeexxxxeeeeccccuuuuttttaaaabbbblllleeee tttthhhhaaaatttt ddddooooeeeessssnnnn''''tttt uuuusssseeee sssshhhhaaaarrrreeeedddd lllliiiinnnnkkkkiiiinnnngggg????
  491.      Use the ----nnnnoooonnnn____sssshhhhaaaarrrreeeedddd ffffllllaaaagggg::::
  492.  
  493.               cc -non_shared myfile.c -lmine
  494.  
  495.           Some libraries are not and will not be available non-shared.  The
  496.           ones that are available are not installed by default, so one must
  497.           request their installation.  In general, the user of -non_shared is
  498.           deprecated.
  499.  
  500.    9999))))  HHHHoooowwww ddddoooo IIII tttteeeellllllll iiiiffff aaaannnn eeeexxxxeeeeccccuuuuttttaaaabbbblllleeee wwwwiiiillllllll uuuusssseeee ddddyyyynnnnaaaammmmiiiicccc lllliiiinnnnkkkkiiiinnnngggg????
  501.      elfdump -o shows you the ELF program header. This contains all the
  502.      information necessary for _e_x_e_c and _r_l_d to run the program/shared object.
  503.      Only a.outs which use dynamic linking will have a PHDR, INTERP, or
  504.      DYNAMIC entry.
  505.  
  506.      An example and a more detailed description follows:
  507.  
  508.      % elfdump -o /bin/cat
  509.  
  510.                   ***PROGRAM HEADER***
  511. Type     Offset      Vaddr      Paddr     Filesz      Memsz      Align RWX
  512.    PHDR 0x00000034 0x00400034 0x00400034 0x000000c0 0x00000000 0x00000004 r--
  513.  INTERP 0x00000100 0x00400100 0x00400100 0x00000009 0x00000009 0x00000004 r--
  514. REGINFO 0x00000110 0x00400110 0x00400110 0x00000018 0x00000018 0x00000004 r--
  515. DYNAMIC 0x00000150 0x00400150 0x00400150 0x00000a70 0x00000a70 0x00000010 r--
  516.    LOAD 0x00000000 0x00400000 0x00400000 0x00003000 0x00003000 0x00001000 r-x
  517.    LOAD 0x00003000 0x10000000 0x10000000 0x00001000 0x00001290 0x00010000 rwx
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.                                                                         PPPPaaaaggggeeee 8888
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532. DDDDSSSSOOOO((((5555))))                                                                  DDDDSSSSOOOO((((5555))))
  533.  
  534.  
  535.  
  536.      Each line is an entry in the program header, and refers to a "segment" of
  537.      the file.
  538.  
  539.      PPPPHHHHDDDDRRRR points to the program header itself within the file. Only
  540.           executables which use dynamic linking will have this field.
  541.  
  542.      IIIINNNNTTTTEEEERRRRPPPP
  543.           points to a place in the file where the name of the interpreter
  544.           required for this program is to be found. For any ABI-conforming
  545.           object, this name will be "/usr/lib/libc.so.1".
  546.  
  547.      RRRREEEEGGGGIIIINNNNFFFFOOOO
  548.           points to a place in the file where information about register setup
  549.           can be found. Currently this mostly consists of the correct gp value
  550.           for this object.
  551.  
  552.      DDDDYYYYNNNNAAAAMMMMIIIICCCC
  553.           points to the information in the file which is needed by rld to
  554.           execute it correctly. This information includes the liblist, a
  555.           symbol table, and other information.
  556.  
  557.      LLLLOOOOAAAADDDD points to segments that are to be mapped into the memory image.
  558.  
  559.      The columns give various information about each segment.
  560.  
  561.      OOOOffffffffsssseeeetttt
  562.           is the offset in the file to the beginning of the segment.
  563.  
  564.      VVVVaaaaddddddddrrrr
  565.           is the virtual address of the beginning of the segment in the memory
  566.           image of the file, ASSUMING that it was mapped as described in the
  567.           LOAD entries
  568.  
  569.      PPPPaaaaddddddddrrrr
  570.           is the same as Vaddr in our implementation.
  571.  
  572.      FFFFiiiilllleeeesssszzzz
  573.           is the size of the segment in the file.
  574.  
  575.      MMMMeeeemmmmsssszzzz
  576.           is the size of the segment in the memory image.  When this is larger
  577.           it is assumed to be zero-filled.
  578.  
  579.      AAAAlllliiiiggggnnnn
  580.           is the alignment required by this section. If an segment is to be
  581.           mapped somewhere into memory other than at Vaddr, the new address
  582.           must be congruent to Vaddr modulo the alignment. In the example
  583.           above, the first segment must always be loaded at a page boundary,
  584.           and the second must always be loaded at a 64K boundary.
  585.  
  586.  
  587.  
  588.  
  589.  
  590.  
  591.                                                                         PPPPaaaaggggeeee 9999
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598. DDDDSSSSOOOO((((5555))))                                                                  DDDDSSSSOOOO((((5555))))
  599.  
  600.  
  601.  
  602.      RRRRWWWWXXXX  specifies the protections r(ead), w(rite), or x(ecute) for the
  603.           segment.
  604.  
  605.      Programs which are linked ----nnnnoooonnnn____sssshhhhaaaarrrreeeedddd do not have a PHDR, INTERP, or
  606.      DYNAMIC section.  Thus elfdump -o iiiissss aaaa ccccoooonnnnvvvveeeennnniiiieeeennnntttt mmmmeeeetttthhhhoooodddd ttttoooo ddddeeeetttteeeerrrrmmmmiiiinnnneeee iiiiffff
  607.      aaaa pppprrrrooooggggrrrraaaammmm iiiissss lllliiiinnnnkkkkeeeedddd ----nnnnoooonnnn____sssshhhhaaaarrrreeeedddd or not.
  608.  
  609.  
  610.    11110000)))) HHHHoooowwww ddddoooo IIII bbbbuuuuiiiilllldddd aaaa sssshhhhaaaarrrreeeedddd oooobbbbjjjjeeeecccctttt????
  611.      To begin with, build a .o or .a which contains all the routines you want
  612.      to have in your .so (shared object).  This can be done with cccccccc ----cccc and aaaarrrr....
  613.      Then invoke ld with the ----sssshhhhaaaarrrreeeedddd flag. Normally the extension .so is used
  614.      to designate shared objects.
  615.  
  616.      Here is an example:
  617.  
  618.          cc -c myobj.c
  619.          ld -shared myobj.o -o myobj.so
  620.  
  621.          -or-
  622.  
  623.          <build libmine.a the usual way.>
  624.          ld -shared -all libmine.a -o libmine.so
  625.  
  626.      The ----aaaallllllll flag in the second example tells ld to include all the routines
  627.      in the library. This is necessary since there are no undefined references
  628.      (as in a main(), say) which is the usual way that ld knows to include
  629.      files from an archive.
  630.  
  631.    11111111)))) WWWWhhhheeeerrrreeee ddddooooeeeessss tttthhhheeee ssssyyyysssstttteeeemmmm llllooooooookkkk ffffoooorrrr sssshhhhaaaarrrreeeedddd oooobbbbjjjjeeeeccccttttssss aaaatttt rrrruuuunnnnttttiiiimmmmeeee????
  632.      The search path for shared objects is acquired in the following order for
  633.      the old 32bit ABI:
  634.  
  635.      1) the path of the shared object if given in the liblist,
  636.  
  637.      2) in any directories specified via the
  638.           ----rrrrppppaaaatttthhhh flag when the executable was built
  639.  
  640.      3) in any directory specified by the LD_LIBRARY_PATH environment
  641.           variable, if it is defined
  642.  
  643.      4) in the directories in the default path
  644.           (/usr/lib:/lib:/lib/cc:/usr/lib/cc)
  645.  
  646.      If the _RLD_ROOT environment variable is defined, then its value is
  647.      appended to the front of any path specified by ----rrrrppppaaaatttthhhh and the default
  648.      path.  _RLD_ROOT itself is also a colon(:) separated list.
  649.  
  650.      For the new 32bit ABI the rules are similar, but the following
  651.      differences exist:  1)  the LD_LIBRARYN32_PATH is used if defined,
  652.      otherwise LD_LIBRARY_PATH is used 2) _RLDN32_ROOT is used for the list of
  653.      paths 3)The default path directory list is (/usr/lib32:/lib32).
  654.  
  655.  
  656.  
  657.                                                                        PPPPaaaaggggeeee 11110000
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664. DDDDSSSSOOOO((((5555))))                                                                  DDDDSSSSOOOO((((5555))))
  665.  
  666.  
  667.  
  668.      For the 64bit ABI the rules are similar, but the following differences
  669.      exist:  1) The LD_LIBRARY64_PATH is used if defined, otherwise
  670.      LD_LIBRARY_PATH is used 2) _RLD64_ROOT is used for the list of paths 3)
  671.      The default path directory list is (/usr/lib64:/lib64).
  672.  
  673.      See the rld(1) manpage for details.
  674.  
  675.    11112222)))) WWWWhhhhaaaatttt iiiissss QQQQuuuuiiiicccckkkkssssttttaaaarrrrtttt????
  676.      Quickstart is an optimization. Using an so_locations file, each shared
  677.      object is pre-relocated by ld, as if it had been loaded at the address in
  678.      the so_locations file.  That way, if nothing unusual happens when we
  679.      start up the application, all the shared objects will map at their
  680.      Quickstart addresses, and rld will not need to do a relocation pass over
  681.      them.
  682.  
  683.      If for some reason more than one shared object wishes to map the same
  684.      address, rld will move one of them to an unused address and perform a
  685.      relocation pass to fix up the address references.
  686.  
  687.      If one or more of the shared objects linked against at static link time
  688.      has changed by the time the program executes, rld will need to do extra
  689.      work to ensure that symbols have been resolved to their proper value.
  690.  
  691.    11113333)))) WWWWhhhhaaaatttt iiiissss tttthhhheeee ssssoooo____llllooooccccaaaattttiiiioooonnnnssss ffffiiiilllleeee????
  692.      In the directory in which you build a shared object, after you've
  693.      actually built one, you will notice a file named so_locations.
  694.  
  695.      It is a registry of shared objects.  It maintains the default or
  696.      Quickstart addresses of a group of shared objects which are to cooperate
  697.      by not having their default location overlap with one another.  It is
  698.      generated and updated by ld each time it builds a shared object.
  699.  
  700.      If you make substantial library changes between one build of the library
  701.      and another you should remove the so_locations file before rebuilding the
  702.      library, since the information derived from the older build  (and put in
  703.      the so_locations files) may make the new library build unable to complete
  704.      successfully.
  705.  
  706.      Since _r_q_s_a_l_l(1)/_r_q_s(1) can rearrange a.outs and DSOs to restore
  707.      quickstartability the so_locations file is less important than it was
  708.      before _r_q_s existed.
  709.  
  710.    11114444)))) WWWWhhhhaaaatttt ddddiiiirrrreeeeccccttttiiiivvvveeeessss ccccaaaannnn bbbbeeee ppppuuuutttt iiiinnnn aaaannnn ssssoooo____llllooooccccaaaattttiiiioooonnnnssss ffffiiiilllleeee????
  711.      Comment line
  712.           so_name [ :st = { .text | .data | $range } base_addr,padded_size : ] *
  713.  
  714.      where
  715.           so_name         full path name (or trailing component) of a
  716.                           shared object
  717.           st              string identifying start of the segment description
  718.           .text | .data   segment types: text or data
  719.           $range           limit the range of address that can be used
  720.  
  721.  
  722.  
  723.                                                                        PPPPaaaaggggeeee 11111111
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730. DDDDSSSSOOOO((((5555))))                                                                  DDDDSSSSOOOO((((5555))))
  731.  
  732.  
  733.  
  734.           base_addr       address where the segment starts
  735.           padded_size     padded size of the segment
  736.  
  737.      The following directives control the placement of new shared objects:
  738.  
  739.           $text_align_size=<align>  padding=<pad-size>
  740.           $data_align_size=<align>  padding=<pad-size>
  741.               These two directives specify the alignment and padding
  742.            requirements for text and data segments respectively.
  743.            The size value in so location is calculated based on:
  744.               (section size + padding) aligned to the section align size
  745.               The align values for text and data as well as the padding
  746.               values must be aligned to a bucket size. If not, ld will
  747.            generate a warning message and align these values to bucket
  748.            size.
  749.  
  750.           $start_address=<addr>
  751.               Specifies where to start looking for addresses to put shared
  752.               objects.
  753.  
  754.           $data_after_text=[ 1 | 0 ]
  755.               Instructs the linker to place data immediately after the text
  756.               at specified text and data alignment requirements.
  757.               We set the data_after_text to 0 if the argument of this directive
  758.               is missing.
  759.      WWWWAAAARRRRNNNNIIIINNNNGGGG:::: TTTThhhheeee ffffoooorrrrmmmmaaaatttt aaaannnndddd uuuusssseeee ooooffff tttthhhheeee ssssoooo____llllooooccccaaaattttiiiioooonnnnssss  ffffiiiilllleeee iiiissss uuuunnnnddddeeeerrrr rrrreeeevvvviiiieeeewwww aaaannnndddd
  760.      mmmmaaaayyyy iiiinnnn tttthhhheeee ffffuuuuttttuuuurrrreeee mmmmoooovvvveeee ttttoooo aaaa ssssiiiimmmmpppplllleeeerrrr ffffoooorrrrmmmmaaaatttt.... IIIItttt iiiissss ssssuuuuggggggggeeeesssstttteeeedddd iiiinnnn tttthhhheeee mmmmeeeeaaaannnn
  761.      ttttiiiimmmmeeee tttthhhhaaaatttt oooonnnnllllyyyy $$$$rrrraaaannnnggggeeee bbbbeeee uuuusssseeeedddd aaaannnndddd nnnnooootttt ....tttteeeexxxxtttt oooorrrr ....ddddaaaattttaaaa iiiinnnn tttthhhheeee
  762.      ssssppppeeeecccciiiiffffiiiiccccaaaattttiiiioooonnnn....
  763.  
  764.      Also, when building a DSO with the ----cccchhhheeeecccckkkk____rrrreeeeggggiiiissssttttrrrryyyy or ----uuuuppppddddaaaatttteeee____rrrreeeeggggiiiissssttttrrrryyyy
  765.      flag, and if there is already an entry corresponding to this DSO in an
  766.      so_location file, the linker will try to assign the same addresses for
  767.      text and data.  However, if the size of the DSO changes and does not fit
  768.      in the specified location any more, the linker will search for another
  769.      spot that fits.  If the optional $range comment is given, the linker will
  770.      only place the DSO in the specified range of addresses.  If there is not
  771.      enough room, an error will be given.
  772.  
  773.    11115555)))) WWWWhhhhaaaatttt iiiissss ////uuuussssrrrr////lllliiiibbbb////ssssoooo____llllooooccccaaaattttiiiioooonnnnssss????
  774.      /usr/lib/so_locations (for the old 32bit ABI), /usr/lib32/so_locations
  775.      (for the new 32bit ABI), and /usr/lib64/so_locations (for the 64bit ABI)
  776.      represent the default layout for the system shared objects in the
  777.      respective ABIs.  Developers who build shared objects may find it
  778.      interesting to consult this file, in order to avoid collisions between
  779.      their shared objects and system shared objects.  This file is absolutely
  780.      irrelevant to users who merely run programs which use shared objects.
  781.  
  782.      There are two options which are relevant, ----uuuuppppddddaaaatttteeee____rrrreeeeggggiiiissssttttrrrryyyy,,,, and <file>
  783.      looks at <file> and builds the current .so at a location which doesn't
  784.      conflict with anything in the file (unless the current one is listed.  ----
  785.      cccchhhheeeecccckkkk____rrrreeeeggggiiiissssttttrrrryyyy does not write to <file>.  ----uuuuppppddddaaaatttteeee____rrrreeeeggggiiiissssttttrrrryyyy <file> will
  786.  
  787.  
  788.  
  789.                                                                        PPPPaaaaggggeeee 11112222
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796. DDDDSSSSOOOO((((5555))))                                                                  DDDDSSSSOOOO((((5555))))
  797.  
  798.  
  799.  
  800.      consult <file> as with ----cccchhhheeeecccckkkk____rrrreeeeggggiiiissssttttrrrryyyy,,,, but will attempt to write an
  801.      entry for the .so being built into <file>.  If <file> is not writable, ----
  802.      uuuuppppddddaaaatttteeee____rrrreeeeggggiiiissssttttrrrryyyy turns into If <file> is not readable ----cccchhhheeeecccckkkk____rrrreeeeggggiiiissssttttrrrryyyy and
  803.      ----uuuuppppddddaaaatttteeee____rrrreeeeggggiiiissssttttrrrryyyy are ignored.
  804.  
  805.    11116666)))) IIIIffff IIII ddddoooonnnn''''tttt hhhhaaaavvvveeee aaaa vvvvaaaalllliiiidddd ssssoooo____llllooooccccaaaattttiiiioooonnnnssss ffffiiiilllleeee,,,, ccccaaaannnn IIII ggggeeeennnneeeerrrraaaatttteeee oooonnnneeee ffffrrrroooommmm aaaallllllll
  806.      tttthhhheeee ....ssssoooo''''ssss iiiinnnn,,,, ssssaaaayyyy,,,, ////uuuussssrrrr////lllliiiibbbb????
  807.      There is no convenient method to do so.  There is no guarantee that all
  808.      the .so's in /usr/lib have been coordinated so that a consistent
  809.      so_locations file can be made from them.  So it is better to get the one
  810.      that a particular release was made with.
  811.  
  812.    11117777)))) HHHHoooowwww eeeexxxxppppeeeennnnssssiiiivvvveeee iiiissss iiiitttt ((((aaaatttt rrrruuuunnnnttttiiiimmmmeeee)))) NNNNOOOOTTTT ttttoooo uuuusssseeee ----uuuuppppddddaaaatttteeee____rrrreeeeggggiiiissssttttrrrryyyy ooooppppttttiiiioooonnnn????
  813.      If one uses rqsall(1)/rqs(1) to requickstart an application and its DSOs
  814.      then there need not be any cost. rqs(1) can make the DSOs quickstartable
  815.      regardless how the DSO addresses were determined.
  816.  
  817.      If one does not use rqs then the lack of an updated registry can impose
  818.      startup costs.  It is very difficult to say how much a particular
  819.      executable will suffer since it depends on which shared objects the
  820.      program uses and whether they have been Quickstarted for the same
  821.      address.  When there is a conflict between two objects, one will be
  822.      moved, which means that all addresses referring to names in that object
  823.      need to be relocated.
  824.  
  825.    11118888)))) HHHHoooowwww aaaannnndddd wwwwhhhheeeennnn wwwwiiiillllllll QQQQuuuuiiiicccckkkkssssttttaaaarrrrtttt bbbbeeee uuuusssseeeedddd????
  826.      Normally, the linker will use Quickstart unless there are unresolved
  827.      symbols at static link time.
  828.  
  829.      In every executable and every shared object is a list of objects which
  830.      were looked at at static link time -- when the object was made.  This
  831.      list also contains timestamps and checksums for each of the objects.
  832.      Various levels of extra work are required if the timestamp or checksum
  833.      has changed in the library at run-time.
  834.  
  835.    11119999)))) WWWWhhhhaaaatttt aaaabbbboooouuuutttt rrrruuuunnnn----ttttiiiimmmmeeee llllooooaaaaddddiiiinnnngggg uuuunnnnddddeeeerrrr uuuusssseeeerrrr ccccoooonnnnttttrrrroooollll????
  836.      We support an interface known as libdl, which allows users to dynamically
  837.      load their own shared objects as needed. The calls are
  838.  
  839.      dlopen() -- open a new shared object and get a "handle" to it.
  840.  
  841.      dlsym()  -- find the value of a name defined in an object.
  842.  
  843.      dlclose()-- close a shared object.
  844.  
  845.      dlerror()-- report errors.
  846.  
  847.      sgidladd() -- functions much like dlopen however it exposes
  848.           all symbols to the rest of the program.
  849.  
  850.  
  851.  
  852.  
  853.  
  854.  
  855.                                                                        PPPPaaaaggggeeee 11113333
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862. DDDDSSSSOOOO((((5555))))                                                                  DDDDSSSSOOOO((((5555))))
  863.  
  864.  
  865.  
  866.      sgidlopen_version -- functions much like dlopen however
  867.           it allows specifying a specific required version of the DSO.
  868.  
  869.      Consult the individual manpages for details.
  870.  
  871.    22220000)))) WWWWhhhhaaaatttt bbbbeeeennnneeeeffffiiiittttssss wwwwiiiillllllll IIII ggggeeeetttt ffffrrrroooommmm DDDDSSSSOOOO????
  872.      Executables linked with shared objects will be smaller since the shared
  873.      objects are not part of the executable file image.
  874.  
  875.      Executables which use a shared object need not be relinked if a shared
  876.      object is changed -- once the updated shared object is installed, the
  877.      executable will pick it up automatically.
  878.  
  879.      Shared libraries are much easier to build, use, and debug than static
  880.      shared libraries.
  881.  
  882.      DSO allows application designers to make more machine-independent
  883.      software.  System-dependent routines can be given a uniform interface and
  884.      a shared object which implements that interface can be built for each
  885.      different platform.  Then an actual application can be shipped as-is
  886.      ("shrink-wrapped" software) to various platforms and run on them all.
  887.  
  888.      DSO gives applications the ability to change the binding of symbols at
  889.      run time, under user control.
  890.  
  891.    22221111)))) WWWWhhhhaaaatttt ccccoooossssttttssss aaaarrrreeee aaaassssssssoooocccciiiiaaaatttteeeedddd wwwwiiiitttthhhh DDDDSSSSOOOO????
  892.      A shared object incurs two costs, both against performance.
  893.  
  894.      At startup, there will be a startup cost while rld maps in the various
  895.      objects, performs symbol resolution, etc.  We believe this cost is small
  896.      compared to the time it takes to contact the X server, for example.
  897.  
  898.      A shared object's text must be PIC (position independent code).
  899.      PICification is accomplished by the code generator/assembler when the ----
  900.      KKKKPPPPIIIICCCC flag is specified. ----KKKKPPPPIIIICCCC is the default, so it is not necessary to
  901.      supply the ----KKKKPPPPIIIICCCC flag.  PIC code is necessarily slower. Experiments have
  902.      indicated that this speed reduction is usually less than 5 percent, but
  903.      can be as much as 15 percent.  depending on the application. With full
  904.      optimization the speed reduction can be near zero.  PIC code seems to be
  905.      worst on very small leaf routines which access global data.
  906.  
  907.    22222222)))) WWWWhhhhaaaatttt iiiissss tttthhhheeee ----KKKKPPPPIIIICCCC ooooppppttttiiiioooonnnn????
  908.      This the default, so you need never use it.  This flags tells the code
  909.      generator/assembler to generate PIC directly.  The result is an object
  910.      file that can be put into a DSO without further modification
  911.  
  912.               cc -KPIC -c foo.c
  913.  
  914.      will give you a PIC object foo.o.  Other drivers (cc, pc, f77, and as)
  915.      also accept the -KPIC option.  This is the default.
  916.  
  917.  
  918.  
  919.  
  920.  
  921.                                                                        PPPPaaaaggggeeee 11114444
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928. DDDDSSSSOOOO((((5555))))                                                                  DDDDSSSSOOOO((((5555))))
  929.  
  930.  
  931.  
  932.      Routines written in assembly language need to be modified before -KPIC
  933.      can be used. See the question below.
  934.  
  935.      PIC objects generated by using -KPIC must be compiled -G 0.
  936.  
  937.    22223333)))) MMMMuuuusssstttt mmmmaaaaiiiinnnn pppprrrrooooggggrrrraaaammmmssss wwwwhhhhiiiicccchhhh wwwwaaaannnntttt ttttoooo uuuusssseeee DDDDSSSSOOOOssss uuuusssseeee ----KKKKPPPPIIIICCCC ffffoooorrrr ccccoooommmmppppiiiillllaaaattttiiiioooonnnn????
  938.      Yes.  DSOs use -KPIC so that position-independent code will be generated.
  939.      Main programs are not generally position-independent, but must still use
  940.      the DSO calling convention when calling a routine which is defined in a
  941.      DSO. In particular, this means that a main program must have a GOT, and
  942.      the code which is generated must use it.  Therefore, modules which will
  943.      become part of main programs must be compiled -KPIC as well as modules
  944.      which become part of DSOs.
  945.  
  946.    22224444)))) HHHHoooowwww ddddoooo IIII cccchhhhaaaannnnggggeeee mmmmyyyy aaaasssssssseeeemmmmbbbbllllyyyy llllaaaannnngggguuuuaaaaggggeeee ssssoooouuuurrrrcccceeeessss ttttoooo uuuusssseeee ----KKKKPPPPIIIICCCC????
  947.      The following refers to the older 32 bit abi using ucode compilers.  For
  948.      n32 and 64 bit abi information, look at the information and pointers in
  949.      the aaaabbbbiiii((((5555)))) manpage.
  950.  
  951.      Several new assembler directives are added to support generation of PIC.
  952.      You should also get yourself familiar with the MIPS ABI Supplement and
  953.      the PIC coding model it describes.  In addition, files which are to be
  954.      assembled with -KPIC must also be -G 0.  This is normally turned on by
  955.      the driver by default.
  956.  
  957.      Note that with the exception of (a) and (d), all other directives
  958.      described below will be ignored when -KPIC is not explicitly specified.
  959.      Also, item (d), ".gpword", will be turned into ".word". The result will
  960.      be a NON-PIC version of the same routine.
  961.  
  962.      a) .option pic2
  963.  
  964.      This directive forces the assembler to mark the output object file "PIC"
  965.      and activates the following directives.  It overrides the command line
  966.      argument.  Normally, you don't need to specify this directive.  Instead,
  967.      you should use the ----KKKKPPPPIIIICCCC or ----nnnnoooonnnn____sssshhhhaaaarrrreeeedddd flags to toggle between
  968.      generating PIC or non-PIC.
  969.  
  970.      Note that even though ----KKKKPPPPIIIICCCC will be made the default for the high-
  971.      language driver (cc/pc/f77) in future releases, it will *NOT* be the
  972.      default for assembly sources.  You will always have to explicitly specify
  973.      ----KKKKPPPPIIIICCCC for compiling .s files.
  974.  
  975.      b) .cpload reg
  976.  
  977.      This directive expands into three instructions that sets the gp register
  978.      to the context pointer value for the current function.  The three
  979.      instructions are:
  980.           lui  gp,_gp_disp
  981.           addui     gp,gp,_gp_disp
  982.           addu gp,gp,reg
  983.  
  984.  
  985.  
  986.  
  987.                                                                        PPPPaaaaggggeeee 11115555
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994. DDDDSSSSOOOO((((5555))))                                                                  DDDDSSSSOOOO((((5555))))
  995.  
  996.  
  997.  
  998.      _gp_disp is a reserved symbol defined by the linker to be the distance
  999.      between the lui instruction and the context pointer.  This directive is
  1000.      required at the beginning of each subroutine that uses the gp register.
  1001.  
  1002.      You must add this directive at the beginning of every procedure, with the
  1003.      exception of leaf-procedures that do not access any global variables, and
  1004.      procedures that are static (i.e., not marked .globl or .extern).
  1005.  
  1006.      c) .cprestore offset
  1007.  
  1008.      This directive causes the assembler to issue
  1009.                sw   gp,offset(sp)
  1010.      at the point where it appears.  Additionally, it causes the assembler to
  1011.      emit
  1012.                lw   gp,offset(sp)
  1013.      after every jump-and-link (jal) or branch-and-link (bal) operation,
  1014.      thereby restoring the gp register after function calls.  The programmer
  1015.      is responsible for allocating the stack space for the gp.  This space
  1016.      should be in the saved register area of the stack frame to remain
  1017.      consistent with MIPS' calling and debugger conventions.
  1018.  
  1019.      d) .gpword local-sym
  1020.  
  1021.      This directive is similar to .word except that the relocation entry for
  1022.      local-sym has the R_MIPS_GPREL32 type.  After linkage, this results in a
  1023.      32-bit value that is the distance between local-sym and the context
  1024.      pointer (i.e. the gp).  local-sym must be local.  It is currently used
  1025.      for PIC switch tables.
  1026.  
  1027.      e) .cpadd reg
  1028.  
  1029.      This adds the value of the context pointer (gp) to reg.
  1030.  
  1031.      EXAMPLES:
  1032.           This is a simplified version of the "hello world" program:
  1033.           --------------------------------------------------------------
  1034.                .option   pic2
  1035.                .data
  1036.                .align    2
  1037.           $$5:
  1038.                .ascii    "hello world\X0A\X00"
  1039.                .text
  1040.                .align    2
  1041.           main:
  1042.                .set  noreorder
  1043.                .cpload   $25
  1044.                .set  reorder
  1045.                subu $sp, 40
  1046.                sw   $31, 36($sp)
  1047.                .cprestore     32
  1048.                la   $4, $$5
  1049.                jal  printf
  1050.  
  1051.  
  1052.  
  1053.                                                                        PPPPaaaaggggeeee 11116666
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060. DDDDSSSSOOOO((((5555))))                                                                  DDDDSSSSOOOO((((5555))))
  1061.  
  1062.  
  1063.  
  1064.               move  $2, $0
  1065.                lw   $31, 36($sp)
  1066.                addu $sp, 40
  1067.                j    $31
  1068.           ----------------------------------------------------------------
  1069.           The actual instructions generated by the assembler will be:
  1070.  
  1071.                lui  gp,0      #
  1072.                addiu     gp,gp,0        # generated by .cpload
  1073.                addu gp,gp,t9  #
  1074.                lw   a0,0(gp)  # gp-relative addressing used
  1075.                lw   t9,0(gp)  # t9 is used for func. call
  1076.                addiu     sp,sp,-40
  1077.                sw   ra,36(sp)
  1078.                sw   gp,32(sp) # from .cprestore
  1079.                jalr ra,t9          # jal is changed to jalr
  1080.                addiu     a0,a0,0
  1081.                lw   ra,36(sp)
  1082.                lw   gp,32(sp) # activated by .cprestore
  1083.                move v0,zero
  1084.                jr   ra
  1085.                addiu     sp,sp,40
  1086.                nop
  1087.           ----------------------------------------------------------------
  1088.  
  1089.      NOTE:
  1090.  
  1091.      The MIPS ABI requires that register t9 ($25) be used for indirect
  1092.      function calls, so .cpload should always use $25.  No reorder mode should
  1093.      also be used.  Also, programmers should make sure that t9 is dead before
  1094.      any function call because the register will be changed (and not restored)
  1095.      during the function call.
  1096.  
  1097.      If your program uses an indirect jump (jalr), you must also use t9 as the
  1098.      jump register.
  1099.  
  1100.      If you have an unconditional jump to an external label:
  1101.                j  _cerror
  1102.          you have to rewrite it into indirect jump via t9, i.e.:
  1103.                la t9,_cerror
  1104.                j  t9
  1105.  
  1106.      If you use branch-and-link (bal) instruction, and if the target procedure
  1107.      begins with a .cpload, you have to specify an alternate entry point:
  1108.  
  1109.           foo: .set noreorder # callee
  1110.                .cpload   $25
  1111.                .set reorder
  1112.           $$1: ...            # alternative entry point
  1113.                ...
  1114.                j    $31       # foo returns
  1115.  
  1116.  
  1117.  
  1118.  
  1119.                                                                        PPPPaaaaggggeeee 11117777
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126. DDDDSSSSOOOO((((5555))))                                                                  DDDDSSSSOOOO((((5555))))
  1127.  
  1128.  
  1129.  
  1130.          bar:  ...            # caller
  1131.                ...
  1132.                bal  $$1       # by-pass the .cpload
  1133.                ...
  1134.  
  1135.      This is very important because .cpload assumes register $25 contains the
  1136.      address of foo, but in this case $25 is not set up.  Note that since both
  1137.      foo and bar reside in the same file, they must have the same value for
  1138.      $gp.  So the .cpload instructions can be and must be bypassed.  However,
  1139.      since foo can still be called from outside, the .cpload is still
  1140.      required.
  1141.  
  1142.      Alternatively, if you don't want to have an alternate entry point, you
  1143.      can set up register $25 before the bal:
  1144.                la   t9,foo
  1145.                bal  foo
  1146.  
  1147.          but this will be less efficient.
  1148.  
  1149.      position-independent jump table (or any table of text addresses).
  1150.      Entries of the address table created by .gpword are converted into
  1151.      displacement from the context pointer.  To get the correct text address,
  1152.      .cpadd should be used to add the value of gp back to them.  Since the gp
  1153.      is updated by the run-time linker, the correct text address can be
  1154.      reconstructed regardless of the location of the DSO.
  1155.  
  1156.    22225555)))) CCCCaaaannnn IIII mmmmiiiixxxx IIIIRRRRIIIIXXXX 4444 ssssttttaaaattttiiiicccc sssshhhhaaaarrrreeeedddd lllliiiibbbbrrrraaaarrrriiiieeeessss wwwwiiiitttthhhh DDDDSSSSOOOOssss????
  1157.      No.
  1158.  
  1159.    22226666)))) WWWWhhhhaaaatttt ooooppppttttiiiioooonnnnssss ddddoooo IIII hhhhaaaavvvveeee wwwwhhhheeeennnn bbbbuuuuiiiillllddddiiiinnnngggg aaaa sssshhhhaaaarrrreeeedddd oooobbbbjjjjeeeecccctttt????
  1160.      If you specify the flag ----BBBBddddyyyynnnnaaaammmmiiiicccc while linking a shared object, symbols
  1161.      in the shared object will be resolved differently than the default
  1162.      linkage convention.  In particular, the runtime linker will always try to
  1163.      resolve any symbols referenced in that object to symbols defined in that
  1164.      object first, instead of looking for definitions in objects in the order
  1165.      specified on the link line.
  1166.  
  1167.      The effect of this is to make all symbols defined and used in such
  1168.      objects non-preemptable.  Ordinarily a such symbol definitions could be
  1169.      preempted by a definition in an earlier shared object, but when
  1170.      -Bsymbolic is specified, this is not the case.
  1171.  
  1172.    22227777)))) WWWWhhhhaaaatttt ppppiiiittttffffaaaallllllllssss aaaarrrreeee aaaassssssssoooocccciiiiaaaatttteeeedddd wwwwiiiitttthhhh DDDDSSSSOOOO????
  1173.      Behind most surprises is the fact that linking semantics are
  1174.      fundamentally different, but only in a subtle way.  Let us suppose that
  1175.      your program links with three libraries, libA, libB and libC, in that
  1176.      order.  Further suppose that both libA and libC define some symbol x, but
  1177.      don't use it.  Furthermore, let us suppose that libB contains a reference
  1178.      to x.  Archive linking (the old way) will resolve B's reference to x to
  1179.      the definition in C, whereas shared object linking will resolve B's
  1180.      reference to x to the definition in A.
  1181.  
  1182.  
  1183.  
  1184.  
  1185.                                                                        PPPPaaaaggggeeee 11118888
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192. DDDDSSSSOOOO((((5555))))                                                                  DDDDSSSSOOOO((((5555))))
  1193.  
  1194.  
  1195.  
  1196.      Why the difference?  With archive linking, when libA is examined, there
  1197.      is no outstanding reference to x, hence the definition of x is not
  1198.      extracted from the archive.  Later when libC is examined, there is a
  1199.      reference to x, so it is loaded.
  1200.  
  1201.      With shared objects, all the constituent object files have been joined
  1202.      into one object, so all symbol definitions are always present.  The
  1203.      resolution rule is simple, take the definition in the object listed
  1204.      first. Thus the definition in libA is used.
  1205.  
  1206.      Another sort of surprise is the "runtime dangling reference".  It is
  1207.      altogether possible to build and link an application with no errors or
  1208.      even warnings, only to get a message from rld stating that your program
  1209.      has unresolvable symbols.
  1210.  
  1211.      What's going on?  Well, if you build a shared object as part of your
  1212.      program, the linker will not normally complain about undefined symbols
  1213.      during a link of a shared object.  This is because undefined symbols are
  1214.      expected during such a build and are perfectly acceptable.  But if the
  1215.      main program does not use a symbol, it does not get flagged as undefined
  1216.      during static linking.  Thus the runtime "surprise".  You can use the ----
  1217.      nnnnoooo____uuuunnnnrrrreeeessssoooollllvvvveeeedddd flag to the linker to avoid such surprises.
  1218.  
  1219.      Now we turn to a nasty pitfall which can be avoided by some cleverness in
  1220.      building a shared object.  If a particular object in an archive has an
  1221.      external reference to a data symbol (which it expects to be defined in
  1222.      main, libl.a, for example) the linker would not try to resolve that
  1223.      external unless the object file in question was actually referenced by
  1224.      the main program.  If that archive is turned into a shared object
  1225.      naively, the external data reference must be resolved whenever ANY
  1226.      function in the shared object is used, even if no function in the object
  1227.      file in question is ever called and no use is made of the external data
  1228.      symbol in question.
  1229.  
  1230.      This can lead to a scenario where a user has a link that worked with the
  1231.      archives, but builds a program which gets terminated by the runtime
  1232.      linker (_r_l_d).  It is a very bad idea to convert libraries which contain
  1233.      external data symbols to shared objects naively.
  1234.  
  1235.      One thing that can be done is to split the archive into several shared
  1236.      objects which are placed on the liblist of a "master" shared object.
  1237.      Since rld will not by default try to resolve data symbols until the first
  1238.      call is made to a particular object we can create the situation where no
  1239.      attempt to resolve the offending external data symbol is made until a
  1240.      call is made to the object in which it is referenced.
  1241.  
  1242.      Here's an example of how that works: Let us suppose that
  1243.      has_extern_data.o is an object with an undefined external in it which
  1244.      resides in the archive libxyz.a  Here is how to isolate that external
  1245.      data reference:
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.                                                                        PPPPaaaaggggeeee 11119999
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258. DDDDSSSSOOOO((((5555))))                                                                  DDDDSSSSOOOO((((5555))))
  1259.  
  1260.  
  1261.  
  1262.      First make has_extern_data.o into a shared object all its own.
  1263.  
  1264.            % ar x libxyz.a has_extern_data.o
  1265.            % ld -shared has_extern_data.o -o has_extern_data.so
  1266.  
  1267.      Now, make libxyz.so, excluding has_extern_data.o from being included
  1268.      directly, but instead putting it in the liblist of libxyz.so
  1269.  
  1270.          % ld -shared -all -exclude has_extern_data.o libxyz.a has_extern_data.so      -o libxyz.so
  1271.  
  1272.      Another pitfall is attempting to have data references from one
  1273.      _s_g_i_d_l_a_d_d()ed DSO to another. When the first is _s_g_i_d_l_a_d_d()ed the data
  1274.      references are unsatisfied and not resolved. Any use of the data before
  1275.      doing the second _s_g_i_d_l_a_d_d() will get the unresolved value.  And then
  1276.      after _s_g_i_d_l_a_d_d()ing the value will change!
  1277.  
  1278.    22228888)))) WWWWhhhhaaaatttt sssshhhhoooouuuulllldddd IIII ddddoooo aaaabbbboooouuuutttt aaaa GGGGOOOOTTTT oooovvvveeeerrrrfffflllloooowwww????
  1279.      By default, addresses are loaded out of the Global Offset Table (GOT)
  1280.      using a 16 bit offset from a context pointer.  This means that the size
  1281.      of the GOT is limited (by default) to 64K bytes, or about 16 K symbols.
  1282.      When there are too many symbols referenced by a DSO (or a.out) the linker
  1283.      issues the message "GOT overflows"  and will specify an object file which
  1284.      references the symbol which is "out of reach".
  1285.  
  1286.      When developers encounter this problem, they sometimes attempt to split
  1287.      the DSO or a.out in question into several smaller DSOs, each of which can
  1288.      conform to the GOT size limit. Good performance can be achieved this way,
  1289.      and we have routinely recommended this approach.
  1290.  
  1291.      However it is usually more practical (easier and better performance) to
  1292.      use -multigot, and this is now the preferred solution.  Use the ----WWWWllll,,,,----
  1293.      mmmmuuuullllttttiiiiggggooootttt flag on the link line of the program/DSO being constructed when
  1294.      using CC or cc or f77.  Use ----mmmmuuuullllttttiiiiggggooootttt on the ld command line if using ld
  1295.      directly (as one would with a C DSO for example).
  1296.  
  1297.      As a last resort, developers may wish to use the ----xxxxggggooootttt compile-time flag
  1298.      to tell the compiler to issue a different (and slower) code sequence uses
  1299.      a 32-bit offset. This will allow the GOT to contain up to 1G entries. It
  1300.      is critical that every object linked into a final DSO or a.out be
  1301.      compiled with ----xxxxggggooootttt turned on, otherwise code may have been generated
  1302.      which will not work with an extended GOT. However, files compiled with
  1303.      ----xxxxggggooootttt may be linked into a DSO or a.out which has a GOT that does not
  1304.      exceed the 8K symbol limit for 64-bit objects (16K for 32-bit objects)
  1305.      and will work correctly, if somewhat slower.  The GOT size of any shared
  1306.      objects linked is irrelevant.
  1307.  
  1308.      The directory /usr/lib/xgot contains the extended-GOT versions of those
  1309.      objects which SGI has built both normally and ----xxxxggggooootttt.... If a system or third
  1310.      party archive contains small GOT objects which are needed in an extended
  1311.      GOT link, a developer can take the following steps: 1) Look in
  1312.      /usr/lib/xgot to see if an extended GOT version exists.  2) Turn the
  1313.      archive into its own shared object, thus isolating it from the extended
  1314.  
  1315.  
  1316.  
  1317.                                                                        PPPPaaaaggggeeee 22220000
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324. DDDDSSSSOOOO((((5555))))                                                                  DDDDSSSSOOOO((((5555))))
  1325.  
  1326.  
  1327.  
  1328.      GOT binary. 3) contact the archive provider.  In a few cases (crt1.o,
  1329.      crtn.o, c++init.o, and fixade.o), where the performance issues were
  1330.      minimal,  the default objects in /usr/lib are in fact built large GOT.
  1331.  
  1332.      Now that ----mmmmuuuullllttttiiiiggggooootttt exists there is no reason to accept the performance
  1333.      penalty of ----xxxxggggooootttt....
  1334.  
  1335.    22229999)))) HHHHoooowwww aaaarrrreeee mmmmuuuullllttttiiiipppplllleeee vvvveeeerrrrssssiiiioooonnnnssss ooooffff DDDDSSSSOOOOssss ssssuuuuppppppppoooorrrrtttteeeedddd????
  1336.      IRIX 5.0.1 (Compilers v3.16) and later supports the ability to tag shared
  1337.      objects and executables with a version number.  This is intended to
  1338.      support interface changes.  Details are below; items marked (SGI ONLY) do
  1339.      not apply to MSIG ABI binaries, but only to binaries generated on IRIX
  1340.      without the ----aaaabbbbiiii flag turned on.
  1341.  
  1342.      Versioning of Shared Objects.
  1343.  
  1344.      QUICK OVERVIEW
  1345.  
  1346.      For a shared object to be versioned the following needs to be done:
  1347.      Version strings consist of 3 parts and a dot: The string "sgi", a decimal
  1348.      number (the major number), a dot, and a decimal number (the minor
  1349.      number).
  1350.  
  1351.      Add the command -set_version sgi1.0 to the command to build the shared
  1352.      object (cc -shared, ld -shared, etc.).
  1353.  
  1354.      Whenever you make a COMPATIBLE change update the minor version number
  1355.      (the one after the dot), and add the latest version string to colon-
  1356.      separated list of version strings, e.g., -set_version
  1357.      sgi1.0:sgi1.1:sgi1.3
  1358.  
  1359.      Whenever you make an INCOMPATIBLE change, update the major version
  1360.      number.  Pass this as the version list, e.g., -set_version sgi2.0.
  1361.      Change the filename of the OLD shared object by adding a dot followed by
  1362.      the previous major number to the filename of the shared object.  DO NOT
  1363.      CHANGE the soname of the object.  No change to the file contents are
  1364.      necessary or desirable.  Simply rename the file.
  1365.  
  1366.     HOW IT ALL WORKS
  1367.  
  1368.     Versioning is only available for NON-ABI executables.  The current ABI
  1369.     does not require objects to have versioning, nor does it require systems
  1370.     to pay attention to versioning. It does allow objects to contain version
  1371.     strings, but does not require systems to do anything with this
  1372.     information.
  1373.  
  1374.     NON-ABI compliant executables will have the RHF_SGI_ONLY bit turned on in
  1375.     the .dynamic section. This flag will be understood and reported by elfdump
  1376.     -L -long. Only executables with this flag on will get the versioning
  1377.     treatment described below. This RHF_SGI_ONLY will be on by default.
  1378.  
  1379.     When an executable is linked against a shared object, the last entry of
  1380.  
  1381.  
  1382.  
  1383.                                                                        PPPPaaaaggggeeee 22221111
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390. DDDDSSSSOOOO((((5555))))                                                                  DDDDSSSSOOOO((((5555))))
  1391.  
  1392.  
  1393.  
  1394.     the shared object's version string is recorded in the executable as part
  1395.     of the liblist.  This can be examined by elfdump -Dl.
  1396.  
  1397.     When an executable is linked, the user may specify -require_minor or
  1398.     -ignore_minor for each shared object linked against.  If -require_minor is
  1399.     specified, a bit will be set in the flags field of the liblist entry for
  1400.     the shared object in question.  The default is -ignore_minor.
  1401.  
  1402.     When an executable (ABI or RHF_SGI_ONLY) is run rld will look for the
  1403.     proper filename in its usual search routine.
  1404.  
  1405.     (SGI_ONLY) If a file with the correct name is found the version string in
  1406.     the liblist is compared to the list of version strings in the shared
  1407.     object.  If the LL_REQUIRE_MINOR bit is set in the liblist entry, and
  1408.     there is an exact match between the version string in the depender and one
  1409.     of the strings in the version list of the dependee, then that library is
  1410.     used.  If the LL_REQUIRE_MINOR bit is clear, and if there is a match of
  1411.     major versions, then that library is used.
  1412.  
  1413.     (SGI_ONLY) If no proper match is found, a new soname is built by taking
  1414.     the soname found in the executables liblist, and the major number found in
  1415.     the version string corresponding to that liblist entry, and putting them
  1416.     together as <soname>.<major> This is searched for in the same way as
  1417.     above. Version strings are matched in exactly the same way as described
  1418.     above.
  1419.  
  1420.  
  1421.    33330000)))) WWWWhhhhyyyy aaaarrrreeee tttthhhheeee gggglllloooobbbbaaaallll oooobbbbjjjjeeeeccccttttssss iiiinnnn mmmmyyyy CCCC++++++++ DDDDSSSSOOOO nnnnooootttt bbbbeeeeiiiinnnngggg iiiinnnniiiittttiiiiaaaalllliiiizzzzeeeedddd????
  1422.      Did you link your DSO using the CCCCCCCC command (instead of using lllldddd
  1423.      directly)? See the NNNNOOOOTTTTEEEE:::: After the first example in this man page, that
  1424.      discusses how to create a C++ DSO.
  1425.  
  1426.    33331111)))) WWWWhhhhyyyy aaaarrrreeee ssssoooommmmeeee lllliiiibbbbrrrraaaarrrriiiieeeessss oooonnnnllllyyyy aaaavvvvaaaaiiiillllaaaabbbblllleeee aaaassss aaaa DDDDSSSSOOOO,,,, wwwwhhhheeeerrrreeee aaaassss ooootttthhhheeeerrrr
  1427.      lllliiiibbbbrrrraaaarrrriiiieeeessss aaaarrrreeee aaaavvvvaaaaiiiillllaaaabbbblllleeee aaaassss bbbbooootttthhhh aaaa DDDDSSSSOOOO aaaannnndddd aaaannnn aaaarrrrcccchhhhiiiivvvveeee????
  1428.      The ABI specifies which DSOs must be on every system.  The converse of
  1429.      that is that no one can assume that any other .so is on an ABI conforming
  1430.      system. Libraries explicitly called out in the MIPS ABI are considered
  1431.      part of the system interface; and the decision was made to only ship such
  1432.      system interfaces in DSO form. Libraries that are not specified in the
  1433.      MIPS ABI must also be supplied in archive form to generate MIPS ABI
  1434.      compliant binaries using these libraries.
  1435.  
  1436.      For example the libraries: libX11.so,and libc.so.1 are explicitly called
  1437.      out in the MIPS ABI making the DSO version of Xlib and libc a system
  1438.      interface. Other examples are libsocket.so and libdl.so which are also
  1439.      only supplied as DSOs.
  1440.  
  1441.      Archive versions of libXt.a, libXm.a,libm.a libmalloc.a, etc...  are
  1442.      supplied because shared library versions of these libraries are not
  1443.      specified in the MIPS ABI, therefore they are not guaranteed to exist on
  1444.      all ABI conforming systems.
  1445.  
  1446.  
  1447.  
  1448.  
  1449.                                                                        PPPPaaaaggggeeee 22222222
  1450.  
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456. DDDDSSSSOOOO((((5555))))                                                                  DDDDSSSSOOOO((((5555))))
  1457.  
  1458.  
  1459.  
  1460.    33332222)))) WWWWhhhheeeerrrreeee ccccaaaannnn IIII ffffiiiinnnndddd mmmmoooorrrreeee ddddooooccccuuuummmmeeeennnnttttaaaattttiiiioooonnnn oooonnnn DDDDSSSSOOOO????
  1461.      Besides the other manpages mentioned below, _S_y_s_t_e_m _V _A_p_p_l_i_c_a_t_i_o_n _B_i_n_a_r_y
  1462.      _I_n_t_e_r_f_a_c_e and _S_y_s_t_e_m _V _A_p_p_l_i_c_a_t_i_o_n _B_i_n_a_r_y _I_n_t_e_r_f_a_c_e -- MIPS Processor
  1463.      Supplement and _M_I_P_S_p_r_o _N_3_2 _A_B_I _H_a_n_d_b_o_o_k (in IRIS Insight) are good
  1464.      sources of DSO implementation details.
  1465.  
  1466. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  1467.      abi(5), rld(1), ld(1), elf(5), elfdump(1), dlopen(3), sgidladd(3),
  1468.      sgidlopen_version(3),sgidladd(3), sgigetdsoversion(3),gp_overflow(5)
  1469.  
  1470. UUUUPPPPDDDDAAAATTTTEEEESSSS
  1471.      This man page is periodically updated;  the last update done on
  1472.      1996/December/20 for IRIX 6.[234].
  1473.  
  1474.  
  1475.  
  1476.  
  1477.  
  1478.  
  1479.  
  1480.  
  1481.  
  1482.  
  1483.  
  1484.  
  1485.  
  1486.  
  1487.  
  1488.  
  1489.  
  1490.  
  1491.  
  1492.  
  1493.  
  1494.  
  1495.  
  1496.  
  1497.  
  1498.  
  1499.  
  1500.  
  1501.  
  1502.  
  1503.  
  1504.  
  1505.  
  1506.  
  1507.  
  1508.  
  1509.  
  1510.  
  1511.  
  1512.  
  1513.  
  1514.  
  1515.                                                                        PPPPaaaaggggeeee 22223333
  1516.  
  1517.  
  1518.  
  1519.